package com.itouch.bracelet.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.itouch.bracelet.R;
import com.itouch.bracelet.bean.MMessage;

/**
 * cocoaSJ
 */
public class MMessageAdapter extends BaseAdapter 
		 {
	private ArrayList<MMessage> list;
	private Context context;
	//private ImageLoader  imageLoader = ImageLoader.getInstance();
	private LayoutInflater infalter;
	//private DisplayImageOptions options;
	
	
	public MMessageAdapter(Context context, ArrayList<MMessage> list) {
		this.list = list;
		this.context = context;
		  infalter = LayoutInflater.from(context);
//		  options = new DisplayImageOptions.Builder()
//			.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
//			.showImageOnLoading(R.drawable.default_face)
//			.showImageForEmptyUri(R.drawable.default_face)
//			
//			.displayer(new RoundedBitmapDisplayer(5))
//			.showImageOnFail(R.drawable.default_face).cacheInMemory(true)
//			.cacheOnDisc(true).considerExifParams(true)
//			.bitmapConfig(Bitmap.Config.RGB_565).build();
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public MMessage getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View converView, ViewGroup viewGrop) {
		// TODO Auto-generated method stub
		ViewHolder vh = null;
		if (converView == null) {
			vh = new ViewHolder();
			converView =infalter.inflate(
					R.layout.adapter_item_message, viewGrop,false);
			vh.msg_content = (TextView) converView.findViewById(R.id.msg_content);
			vh.msg_time = (TextView) converView.findViewById(R.id.msg_time);
			
			
			converView.setTag(vh);
		} else {
			vh = (ViewHolder) converView.getTag();
		}
		MMessage bean = getItem(position);
		
		vh.msg_content.setText(bean.getContent()+"");
		vh.msg_time.setText(bean.getCreateTime()+"");
		
		return converView;
	}


	class ViewHolder {

		public TextView msg_content;
		public TextView msg_time;
	
	}

}
